package net.sudot.chess.business.controller.web;

import net.sudot.chess.business.controller.AbstractBaseController;
import net.sudot.chess.business.model.Customer;
import net.sudot.chess.business.model.Signin;
import net.sudot.chess.business.service.SigninRecordService;
import net.sudot.chess.business.service.SigninService;
import net.sudot.commons.security.LoginUser;
import net.sudot.commons.utils.ResponseMessage;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * 签到控制器
 *
 * @author tangjialin on 2018-03-05.
 */
@Controller
@RequestMapping(value = "/signin")
public class SigninController extends AbstractBaseController {

    @Resource
    private SigninService signinService;
    @Resource
    private SigninRecordService signinRecordService;

    /**
     * 签到
     *
     * @return 返回签到视图
     */
    @GetMapping("/index")
    public String index() {
        return "signin/index";
    }

    /**
     * 签到
     *
     * @param customer 登录客户信息
     * @return 返回签到结果
     */
    @PostMapping
    @ResponseBody
    public ResponseMessage signin(@LoginUser Customer customer) {
        boolean add = signinRecordService.add(customer);
        return new ResponseMessage(add);
    }

    /**
     * 签到信息
     *
     * @return 返回签到
     */
    @PostMapping("/detail")
    @ResponseBody
    public Signin detail(@LoginUser Customer customer) {
        return signinService.findByCustomer(customer.getId());
    }

}
